class Solution
{
public:
    int countNumbersWithUniqueDigits(int n)
    {
        int result = 1;
        for (int i = 1; i <= n; ++i)
        {
            result += 9 * A(9, i - 1);
        }
        return result;
    }

    int A(int n, int m)
    {
        int result = 1;
        for (int i = n - m + 1; i <= n; ++i)
        {
            result *= i;
        }
        return result;
    }
};